<?php

include_once 'postmodel.php';

$page = new pager();

$list_post = get_all_posts($page, "?page=");

$list_post_ct = get_post_chi_tiet($_GET["pid"]);
//them post
if ($_POST["newpost"] == "newpost") {
    $date = date("Y-m-d H:i:s", time());
    $array = array(
        "id" => "''",
        "user_id" => "{$_COOKIE["id"]}",
        "title" => "'{$_POST["title"]}'",
        "date_post" => "'{$date}'",
        "status" => "1"
    );
    echo them_moi_post($array);
    $id = mysql_insert_id();
    $list = get_mailer();
    /*     * *MAIL** */

    $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch

    $mail->IsSMTP(); // telling the class to use SMTP    
    print_r($list);
    try {        
        $mail->Host = "mail.yourdomain.com"; // SMTP server
        $mail->SMTPDebug = 2;                     // enables SMTP debug information (for testing)
        $mail->SMTPAuth = true;                  // enable SMTP authentication
        $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
        $mail->Host = "smtp.gmail.com";      // sets GMAIL as the SMTP server
        $mail->Port = 465;                   // set the SMTP port for the GMAIL server
        $mail->Username = "hungxdtest@gmail.com";  // GMAIL username
        $mail->Password = "qzol20101989";            // GMAIL password
        $mail->AddReplyTo('hungxdtest@gmail.com', 'First Last');               
            $mail->AddAddress('hungxd2992@gmail.com', 'Nguyễn Văn Hùng');              
        $mail->SetFrom('hungxdtest@gmail.com', 'First Last');
        $mail->AddReplyTo('hungxdtest@gmail.com', 'First Last');
        $mail->Subject = 'Nguyễn Văn Hùng đang test';
        $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
        $mail->Body = "Test nào";
        //$mail->MsgHTML(file_get_contents('contents.html'));
        //$mail->AddAttachment('images/phpmailer.gif');      // attachment
        //$mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
        $mail->Send();        
        echo "Message Sent OK</p>\n";        
    } catch (phpmailerException $e) {
        echo $e->errorMessage(); //Pretty error messages from PHPMailer
    } catch (Exception $e) {
        echo $e->getMessage(); //Boring error messages from anything else!
    }

    echo "aaaaaaaaaaaaaaa";
    //echo "<script>window.location = 'index.php'</script>";
}
if ($_GET["action"] == "delete_post") {
    echo xoa_post($_GET["id"]);
}
?>
